home *** CD-ROM | disk | FTP | other *** search
- /*
- * ProIcon.h - include file defining ProIcon internal data structures.
- *
- * Used when creating external functions to be loaded by ProIcon.
- *
- * For use with Think C 4.0 and ProIcon 2.0.
- */
- #ifndef NULL
- #define NULL 0L
- #endif
-
- #define extended double /* ProIcon uses Think C's 80-bit reals */
-
- typedef long int word; /* ProIcon signed word */
- typedef unsigned long int uword; /* ProIcon unsigned word */
- typedef void *pointer; /* general pointer */
- typedef struct descrip *dptr; /* pointer to descriptor */
- typedef unsigned short int DIGIT; /* large-integer digit */
-
- #define IntBits 16 /* number of bits in a Think C integer */
- #define BitOffMask (IntBits-1)
- #define LogIntBits 4 /* log of IntBits */
- #define MaxCvtLen 257 /* largest string in conversions; the extra */
- /* one is for a terminating null */
- #define MaxInt 077777 /* largest Think C int */
- #define MaxStrLen 0777777777 /* maximum string length */
- #define MaxUnsigned ((unsigned short int)0177777) /* largest unsigned Think C int */
- #define WordSize sizeof(word) /* number of bytes in a ProIcon word */
- #define WordBits 32 /* number of bits in a ProIcon word */
- #define LogWordSize 2 /* log of WordSize */
- #define DescSize sizeof(struct descrip) /* number of bytes in a descriptor */
- #define LogDescSize 3 /* log base 2 of DescSize */
-
- #define CsetSize (256/IntBits) /* number of ints to hold 256 cset bits */
- #define CStateSize 15 /* size of C state for co-expressions */
- #define ActStkBlkEnts 100 /* number of entries in an astkblk */
- #define HSlots 4 /* Initial number of hash buckets in tables and sets */
- #define LogHSlots 2 /* log base 2 of HSlots */
- #define HSegs 6 /* Maximum number of hash bin segments */
-
- /*
- * Codes returned by runtime support routines.
- * Note, some conversion routines also return type codes.
- */
- #define Less -1
- #define Equal 0
- #define Greater 1
- #define CvtFail -2
- #define Cvt -3
- #define NoCvt -4
- #define Failure -5
- #define Defaulted -6
- #define Success -7
- #define Error -8
- /* number of hash bins is HSlots * 2 ^ (HSegs - 1). */
- /*
- * Type codes (descriptors and blocks).
- */
- #define T_Null 0 /* null value */
- #define T_Integer 1 /* integer */
- #define T_Bignum 2 /* long integer */
- #define T_Real 3 /* real number */
- #define T_Cset 4 /* cset */
- #define T_File 5 /* file */
- #define T_Proc 6 /* procedure */
- #define T_List 7 /* list header */
- #define T_Table 8 /* table header */
- #define T_Record 9 /* record */
- #define T_Telem 10 /* table element */
- #define T_Lelem 11 /* list element */
- #define T_Tvsubs 12 /* substring trapped variable */
- #define T_Tvkywd 13 /* keyword trapped variable */
- #define T_Tvtbl 14 /* table element trapped variable */
- #define T_Set 15 /* set header */
- #define T_Selem 16 /* set element */
- #define T_Refresh 17 /* refresh block */
- #define T_Coexpr 18 /* co-expression */
- #define T_External 19 /* external block */
- #define T_Slots 20 /* set/table hash slots */
-
- /*
- * Descriptor types and flags in descriptor type word.
- */
- #define F_Nqual 0x80000000 /* set if NOT string qualifier */
- #define F_Var 0x40000000 /* set if variable */
- #define F_Tvar 0x20000000 /* set if trapped variable */
- #define F_Ptr 0x10000000 /* set if value field is pointer */
-
- #define D_Null (word)(T_Null | F_Nqual)
- #define D_Integer (word)(T_Integer | F_Nqual)
- #define D_Bignum (word)(T_Bignum | F_Ptr | F_Nqual)
- #define D_Real (word)(T_Real | F_Ptr | F_Nqual)
- #define D_Cset (word)(T_Cset | F_Ptr | F_Nqual)
- #define D_File (word)(T_File | F_Ptr | F_Nqual)
- #define D_Proc (word)(T_Proc | F_Ptr | F_Nqual)
- #define D_List (word)(T_List | F_Ptr | F_Nqual)
- #define D_Table (word)(T_Table | F_Ptr | F_Nqual)
- #define D_Telem (word)(T_Telem | F_Ptr | F_Nqual)
- #define D_Tvsubs (word)(T_Tvsubs | D_Tvar)
- #define D_Tvkywd (word)(T_Tvkywd | D_Tvar)
- #define D_Tvtbl (word)(T_Tvtbl | D_Tvar)
- #define D_Record (word)(T_Record | F_Ptr | F_Nqual)
- #define D_Set (word)(T_Set | F_Ptr | F_Nqual)
- #define D_Refresh (word)(T_Refresh | F_Ptr | F_Nqual)
- #define D_Coexpr (word)(T_Coexpr | F_Ptr | F_Nqual)
- #define D_External (word)(T_External | F_Ptr | F_Nqual)
- #define D_Slots (word)(T_Slots | F_Ptr | F_Nqual)
- #define D_Var (word)(F_Var | F_Nqual | F_Ptr)
- #define D_Tvar (word)(D_Var | F_Tvar)
- #define TypeMask 63 /* type mask */
- #define OffsetMask (~(D_Tvar)) /* offset mask for variables */
-
- /*
- * Error codes returnable through *ip that produce the textual
- * message shown with each.
- */
- #define Errnone -1)\
- / sizeof(word))
-
- /*
- * Offset in word of cset bit.
- */
- #define CsetOff(b) ((b) & BitOffMask)
- /*
- * Address of word of cset bit.
- */
- #define CsetPtr(b,c) ((c) + (((b)&0377) >> LogIntBits))
- /*
- * Set bit b in cset c.
- */
- #define Setb(b,c) (*CsetPtr(b,c) |= (01 << CsetOff(b)))
- /*
- * Test bit b in cset c.
- */
- #define Testb(b,c) ((*CsetPtr(b,c) >> CsetOff(b)) & 01)
-
- /* determine the number of words needed for a bignum block with n digits */
-
- #define BigNeed(n) ( ((sizeof(struct b_bignum) + ((n) - 1) * sizeof(DIGIT)) \
- + WordSize - 1) & -WordSize )
-
- /*
- * Macros to access Icon arguments in C functions.
- */
-
- /*
- * n-th argument.
- */
- #define Arg(n) (dargv[n])
-
- /*
- * Specific arguments.
- */
- #define Arg0 (dargv[0])
- #define Arg1 (dargv[1])
- #define Arg2 (dargv[2])
- #define Arg3 (dargv[3])
- #define Arg4 (dargv[4])
- #define Arg5 (dargv[5])
- #define Arg6 (dargv[6])
-
- /*
- * Type field of n-th argument.
- */
- #define ArgType(n) (dargv[n].dword)
-
- /*
- * Value field of n-th argument.
- */
- #define ArgVal(n) (dargv[n].vword.integr)
-
-
- typedef union { /* object code operation, operand */
- short int *op;
- word *opnd;
- } inst;
-
- /*
- * ProIcon descriptor.
- */
- struct descrip {
- word dword; /* type field */
- union { /* value field, one of: */
- word integr; /* integer value */
- char *sptr; /* pointer to character string */
- union block *bptr; /* pointer to a block */
- dptr descptr; /* pointer to a descriptor */
- } vword;
- };
-
- /*
- * ProIcon string qualifier.
- */
- struct sdescrip {
- word length; /* length of string */
- char *string; /* pointer to string */
- };
-
- /*
- * Frame markers
- */
- struct ef_marker { /* expression frame marker */
- inst ef_failure; /* failure ipc */
- struct ef_marker *ef_efp; /* efp */
- struct gf_marker *ef_gfp; /* gfp */
- word ef_ilevel; /* ilevel */
- };
-
- struct pf_marker { /* procedure frame marker */
- word pf_nargs; /* number of arguments */
- struct pf_marker *pf_pfp; /* saved pfp */
- struct ef_marker *pf_efp; /* saved efp */
- struct gf_marker *pf_gfp; /* saved gfp */
- dptr pf_argp; /* saved argp */
- inst pf_ipc; /* saved ipc */
- word pf_ilevel; /* saved ilevel */
- dptr pf_scan; /* saved scanning environment */
- struct descrip pf_locals[1]; /* descriptors for locals */
- };
-
- struct gf_marker { /* generator frame marker */
- word gf_gentype; /* type */
- struct ef_marker *gf_efp; /* efp */
- struct gf_marker *gf_gfp; /* gfp */
- inst gf_ipc; /* ipc */
- struct pf_marker *gf_pfp; /* pfp */
- dptr gf_argp; /* argp */
- };
-
- /*
- * Blocks
- */
- struct b_bignum { /* large integer block */
- word title; /* T_Bignum */
- word blksize; /* block size */
- word msd, lsd; /* most and least significant digits */
- short int sign; /* sign; 0 positive, 1 negative */
- DIGIT digits[1]; /* digits */
- };
-
- struct b_real { /* real block */
- word title; /* T_Real */
- extended realval; /* value */
- };
-
- struct b_cset { /* cset block */
- word title; /* T_Cset */
- word size; /* size of cset */
- short int bits[CsetSize]; /* array of bits */
- };
-
- struct b_file { /* file block */
- word title; /* T_File */
- struct pifile *fd; /* ProIcon file structure */
- word status; /* file status */
- struct descrip fname; /* file name (string qualifier) */
- };
- /* status flags b_file status word */
- #define Fs_Read 01 /* read access */
- #define Fs_Write 02 /* write access */
- #define Fs_Create 04 /* file created on open */
- #define Fs_Append 010 /* append mode */
- #define Fs_Pipe 020 /* reading/writing on a pipe */
- #define Fs_Record 040 /* record structured file */
- #define Fs_Reading 0100 /* last file operation was read */
- #define Fs_Writing 0200 /* allocate a cset block */
- T_alcextrnl, /* allocate an external block */
- T_alcfile, /* allocate a file block */
- T_alchash, /* allocate a hashed structure (set or table header) */
- T_alclist, /* allocate a list header block */
- T_alclstb, /* allocate a list element block */
- T_alcreal, /* allocate a real value block */
- T_alcrecd, /* allocate record with nflds fields */
- T_alcrefresh, /* allocate a co-expression refresh block */
- T_alcsegment, /* allocate a slot block */
- T_alcselem, /* allocate a set element block */
- T_alcstr, /* allocate a string in the string space */
- T_alcsubs, /* allocate a substring trapped variable */
- T_alctelem, /* allocate a table element block */
- T_alctvtbl, /* allocate a table element trapped variable block */
- T_blkreq, /* insure at least n bytes left in the block region */
- T_cvint, /* convert the value at dp into an integer */
- T_cvreal, /* convert the value at dp to a real in place */
- T_cvstr, /* convert dp (in place) into a string, using sbuf as buffer */
- T_emptystr, /* return pointer to descriptor for empty string */
- T_makereal, /* make a real number descriptor and associated block */
- T_nulldesc, /* return pointer to descriptor for null value */
- T_onedesc, /* return pointer to descriptor for integer one */
- T_qtos, /* convert a qualified string named by *dp to a C-style string */
- T_strreq, /* insure at least n bytes left in the string space */
- T_zerodesc /* return pointer to descriptor for integer zero */
- };
-
- #define Fail {return NULL;}
- #define Max(x,y) ((x)>(y)?(x):(y)) /* Maximum of x and y. */
- #define Min(x,y) ((x)<(y)?(x):(y)) /* Minimum of x and y. */
- #define Return {return &Arg0;}
- #define RunErr(n,dp) {*ip = n; return dp;}
-
- pointer callback(int callno, ...);
-
- /*
- * callbacks in interface version 1
- */
-
- /* interface version number */
- #define vcallback() ((word)(callback(T_vers)))
-
- /* allocate a co-expression activation block in the block region */
- #define alcactiv() ((struct astkblk *)callback(T_alcactiv))
-
- /* allocate an n-digit bignum in the block region */
- #define alcbignum(n) ((struct b_bignum *)callback(T_alcbignum, (word)n))
-
- /* allocate a co-expression stack block in the block region */
- #define alccoexp() ((struct b_coexpr *)callback(T_alccoexp))
-
- /* allocate a cset in the block region */
- #define alccset() ((struct b_cset *)callback(T_alccset))
-
- /* allocate an n-word external block in the block region */
- #define alcextrnl(n) ((struct b_external *)callback(T_alcextrnl, (uword)n))
-
- /* allocate a file block in the block region */
- #define alcfile(fd, status, name) ((struct b_file *)callback(T_alcfile, (struct pifile *)fd, (short int)status, (dptr)name))
-
- /* allocate a hashed structure (set or table header) in the block region */
- #define alchash(tcode) ((union block *)callback(T_alchash, (int)tcode))
-
- /* allocate a list header block in the block region */
- #define alclist(size) ((struct b_list *)callback(T_alclist, (uword)size))
-
- /* allocate a list element block in the block region */
- #define alclstb(nslots, first, nused) ((struct b_lelem *)callback(T_alclstb, (uword)nslots, (uword)first, (uword)nused))
-
- /* allocate a real value in the block region */
- #define alcreal(val) ((struct b_real *)callback(T_alcreal, (extended)val))
-
- /* allocate record with nflds fields in the block region */
- #define alcrecd(nflds, recptr) ((struct b_record *)callback(T_alcrecd, (short int)nflds, (union block **)recptr))
-
- /* allocate a co-expression refresh block in the block region */
- #define alcrefresh(entryx, na, nl) ((struct b_refresh *)callback(T_alcrefresh, (word *)entryx, (short int)na, (short int)nl))
-
- /* allocate a slot block in the block region */
- #define alcsegment(nslots) ((struct b_slots *)callback(T_alcsegment, (word)nslots))
-
- /* allocate a set element block in the block region */
- #define alcselem(mbr, hn) ((struct b_selem *)callback(T_alcselem, (dptr)mbr, (uword)hn))
-
- /* allocate an slen-character string in the string region, copy s to it */
- #define alcstr(s, slen) ((char *)callback(T_alcstr, (char *)s, (word)slen))
-
- /* allocate a substring trapped variable in the block region */
- #define alcsubs(len, pos, var) ((struct b_tvsubs *)callback(T_alcsubs, (word)len, (word)pos, (dptr)var))
-
- /* allocate a table element block in the block region */
- #define alctelem() ((struct b_telem *)callback(T_alctelem))
-
- /* allocate a table element trapped variable block in the block region */
- #define alctvtbl(tbl, ref, hashnum) ((struct b_tvtbl *)callback(T_alctvtbl, (dptr)tbl, (dptr)ref, (uword)hashnum))
-
- /* insure that at least bytes of space are left in the block region */
- #define blkreq(n) ((short int)callback(T_blkreq, (uword)n))
-
- /* convert dp (in place) to integer */
- #define cvint(dp) ((short int)callback(T_cvint, (dptr)dp))
-
- /* convert dp (in place) to real */
- #define cvreal(dp) ((short int)callback(T_cvreal, (dptr)dp))
-
- /* convert dp (in place) into a string, using sbuf as buffer */
- #define cvstr(dp, sbuf) ((short int)callback(T_cvstr, (dptr)dp, (char *)sbuf))
-
- /* make a real number descriptor and associated block in the block region */
- #define makereal(val, dp) ((short int)callback(T_makereal, (extended)val, (dptr)dp))
-
- /* convert a qualified string to a C-style string, using sbuf as buffer */
- #define qtos(dp, sbuf) ((short int)callback(T_qtos, (dptr)dp, (char *)sbuf))
-
- /* insure that at least n bytes of space are left in the string space */
- #define strreq(n) ((short int)callback(T_strreq, (uword)n))
-
- /*
- * descriptor pointers provided as callbacks
- */
- #define Emptydp ((dptr)callback(T_emptystr)) /* pointer to empty string descriptor */
- #define Nulldp ((dptr)callback(T_nulldesc)) /* pointer to null value descriptor */
- #define Onedp ((dptr)callback(T_onedesc)) /* pointer to integer one descriptor */
- #define Zerodp ((dptr)callback(T_zerodesc)) /* pointer to integer zero descriptor */
-
- /*
- * end of callbacks in interface version 1
- */
-
-